home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 003-desktop.lzm / usr / bin / khc_htdig.pl < prev    next >
Encoding:
Perl Script  |  2008-10-25  |  3.7 KB  |  149 lines

  1. #!/usr/bin/perl
  2. #
  3. #  Wrapper script for creating search indices for htdig.
  4. #
  5. #  This file is part of the SuSE help system.
  6. #
  7. #  Copyright (C) 2002  SuSE Linux AG, Nuernberg
  8. #
  9. #  Author: Cornelius Schumacher <cschum@suse.de>
  10. #
  11. #  This program is free software; you can redistribute it and/or modify
  12. #  it under the terms of the GNU General Public License as published by
  13. #  the Free Software Foundation; either version 2 of the License, or
  14. #  (at your option) any later version.
  15. #
  16. #  This program is distributed in the hope that it will be useful,
  17. #  but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. #  GNU General Public License for more details.
  20. #
  21. #  You should have received a copy of the GNU General Public License
  22. #  along with this program; if not, write to the Free Software
  23. #  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  24.  
  25. use strict;
  26.  
  27. use Getopt::Long;
  28.  
  29. my $htdigdata = "/srv/www/htdig/common/";
  30. my $htdigbin = "/usr/bin";
  31. my $kdeprefix = "/usr";
  32. chomp $kdeprefix;
  33.  
  34. my $dbg = 1;
  35.  
  36. my ($indexdir, $docpath, $identifier, $lang, $help );
  37.  
  38. GetOptions (
  39.   'indexdir=s' => \$indexdir,
  40.   'docpath=s' => \$docpath,
  41.   'identifier=s' => \$identifier,
  42.   'lang=s' => \$lang,
  43.   'help' => \$help,
  44. );
  45.  
  46. if ( $help ) {
  47.   usage();
  48. }
  49.  
  50. if ( !$indexdir || !$docpath || !$identifier ) {
  51.   print STDERR "Missing arguments.\n";
  52.   usage();
  53. }
  54.  
  55. if ( !$lang ) { $lang = "en"; }
  56.  
  57. &dbg( "INDEXDIR: $indexdir" );
  58.  
  59. print "Creating index for <b>'$identifier'</b>\n";
  60.  
  61. my $htdigconf = $indexdir;
  62. my $htdigdb = $indexdir;
  63.  
  64. my $conffile = "$htdigconf/$identifier.conf";
  65.  
  66. if ( !open( CONF, ">$conffile" ) ) {
  67.   print STDERR "Unable to open '$conffile' for writing.\n";
  68.   exit 1;
  69. }
  70.  
  71. my $commondir = "$htdigdata/$lang";
  72. if ( !$lang || !-e $commondir ) {
  73.   $commondir = "$htdigdata/en";
  74. }
  75. if ( !-e $commondir ) { $commondir = $htdigdata; }
  76.  
  77. my $locale;
  78. if ( $lang eq "de" ) { $locale = "de_DE"; }
  79. else { $locale = $lang; }
  80.  
  81. print CONF << "EOT";
  82. # htdig configuration for doc '$identifier'
  83. #
  84. # This file has been automatically created by KHelpcenter
  85.  
  86. common_dir:        $commondir
  87. locale:                 $locale
  88. database_dir:           $htdigdb
  89. local_urls:        http://localhost=
  90. local_urls_only:    true
  91. limit_urls_to:          http://localhost
  92. ignore_noindex:        true
  93. max_hop_count:        4
  94. robotstxt_name:         kdedig
  95. compression_level:    6
  96. template_map:           Long long $kdeprefix/share/apps/khelpcenter/searchhandlers/htdig/htdig_long.html \\
  97.                         Short short $htdigdata/short.html
  98. search_algorithm:       exact:1 prefix:0.8
  99. maximum_pages:          1
  100. matches_per_page:       10
  101. database_base:        \${database_dir}/$identifier
  102. start_url:        http://localhost/$docpath
  103. # for pdf-files
  104. max_doc_size:           5000000
  105. external_parsers: application/pdf /usr/share/doc/packages/htdig/contrib/parse_doc.pl      application/postscript /usr/share/doc/packages/htdig/contrib/parse_doc.pl
  106. #external_parsers: text/docbook /build/htdig/parser
  107. EOT
  108.  
  109. close CONF;
  110.  
  111. $ENV{ PATH } = '';
  112. $ENV{ CDPATH } = '';
  113. $ENV{ ENV } = '';
  114.  
  115. my $ret = system( "$htdigbin/htdig", "-s", "-i", "-c", $conffile );
  116. if ( $ret != 0 ) {
  117.   print STDERR "htdig failed\n";
  118. } else {
  119.   $ret = system( "$htdigbin/htmerge", "-c", $conffile );
  120.   if ( $ret != 0 ) { print STDERR "htmerge failed\n"; }
  121. }
  122.  
  123. if ( $ret == 0 ) {
  124.   my $existsfile = "$indexdir/$identifier.exists";
  125.  
  126.   if ( !open( EXISTS, ">$existsfile" ) ) {
  127.     print STDERR "Unable to open '$existsfile' for writing.\n";
  128.     exit 1;
  129.   }
  130.   print EXISTS "$identifier\n";
  131.   close EXISTS;
  132.  
  133.   print "Finished successfully.\n";
  134. }
  135.  
  136. exit $ret;
  137.  
  138. sub dbg($)
  139. {
  140.   $dbg && print STDERR shift, "\n";
  141. }
  142.  
  143. sub usage()
  144. {
  145.   print "Usage: khc_htdig.pl --indexdir <indexdir> --docpath <path> ";
  146.   print "--identifier <identifier>\n";
  147.   exit 1;
  148. }
  149.